/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
/*
 * tameshi
 * Copyright (C) 2012 Massimiliano Maniscalco <massi.neptune@gmail.com>
 * 
tameshi is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * tameshi is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PARSER_XML_H_
#define _PARSER_XML_H_

#include <gtkmm.h>
#include <libxml++/libxml++.h>
#include "domanda.h"

using namespace std;

class ParserXML: public xmlpp::SaxParser 
{
public:
	inline ParserXML() :
		codice_elemento ( 0 ), tag_text_elem ( 0 ), indice ( -1 ), quaestio ( new Domanda() ), tags ( new list<Glib::ustring::size_type>() )
	{ }
	virtual inline ~ParserXML();
	
	typedef sigc::signal<void, Domanda> Signal_domanda_imported;
	inline Signal_domanda_imported signal_domanda_imported ( void ) { return commit_import_domanda; }
	typedef sigc::signal<void> Signal_import_end;
	inline Signal_import_end signal_import_end ( void ) { return commit_import_end; }
	
protected:
#ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
	virtual void on_start_document();
	virtual void on_end_document();
	virtual void on_start_element(const Glib::ustring& name, const AttributeList& properties);
	virtual void on_end_element(const Glib::ustring& name);
	virtual void on_characters(const Glib::ustring& characters);
	virtual void on_comment(const Glib::ustring& text);
	virtual void on_warning(const Glib::ustring& text);
	virtual void on_error(const Glib::ustring& text);
	virtual void on_fatal_error(const Glib::ustring& text);
#endif
	time_t parseTimeString ( const Glib::ustring& str );

private:
	int codice_elemento;
	int tag_text_elem;
	short indice;
	Signal_domanda_imported commit_import_domanda;
	Signal_import_end commit_import_end;
	Domanda *quaestio;
	list<Glib::ustring::size_type> *tags;

};

inline ParserXML::
~ParserXML()
{
	if ( quaestio )
		delete quaestio;
	if ( tags )
		delete tags;
}

#endif // _PARSER_XML_H_

